import {cloneDeep} from "lodash";
import {MESSAGE_JSON} from "@/schema/interview";

function padZero(num: number): string {
    return num < 10 ? `0${num}` : `${num}`;
}

function formatDate(date: Date): string {
    const year = date.getFullYear();
    const month = padZero(date.getMonth() + 1); // 补零
    const day = padZero(date.getDate());        // 补零
    return `${year}-${month}-${day}`;
}

function formatTime(date: Date): string {
    const hours = padZero(date.getHours());     // 补零
    const minutes = padZero(date.getMinutes()); // 补零
    const seconds = padZero(date.getSeconds()); // 补零
    return `${hours}:${minutes}:${seconds}`;
}

function formatDateTime(date: Date): string {
    const datePart = formatDate(date);
    const timePart = formatTime(date);
    return `${datePart}_${timePart}`;
}

function trimString(str: string): string {
    // 找到第一个 \n 的位置
    const firstIndex = str.indexOf('\n');
    // 找到最后一个 \n 的位置
    const lastIndex = str.lastIndexOf('\n');

    // 如果没有找到 \n 或者只有一个 \n，则返回原字符串
    if (firstIndex === -1 || firstIndex === lastIndex) {
        return str;
    }

    // 切掉第一个 \n 前的部分和最后一个 \n 后的部分
    return str.substring(firstIndex + 1, lastIndex);
}

export { formatTime, formatDate, formatDateTime, trimString, padZero };